/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package drivers;

import com.github.sarxos.webcam.Webcam;
import java.awt.Dimension;
import javax.swing.JFrame;
import transferObject.ProcessingImageTO;

/**
 *
 * @author Progresywny Maciek
 */
public class WebcamUSB {

    public Webcam webcam;
    private ProcessingImageTO oneFrame;
    private JFrame window;
    private int cameraID;

    public WebcamUSB(int cameraID) {
        this.cameraID = cameraID;
        webcam = Webcam.getWebcams().get(cameraID);
        webcam.open();
        this.oneFrame = new ProcessingImageTO();
    }

    public void setSize(int x, int y) {
        Dimension d = new Dimension(x, y);
        webcam.setViewSize(d);
    }
    
    public Dimension getSize() {
        return webcam.getViewSize();
    }

    public ProcessingImageTO getOneFrame() {
        oneFrame.setFrame(webcam.getImage());
        return oneFrame;
    }

    public void closeCamera() {
        webcam.close();
    }
    
    public void openCamera() {
        webcam.open();
    }

    public static void main(String[] args) throws InterruptedException {
    }
}
